<template>
  <div class="wrapper">
    <!-- 加一层wrapper防止网速慢时有抖动效果 -->
    <swiper :options="swiperOption" v-if="showSwiper">
      <!-- <swiper-slide>
        <img class="swiper-img" src="http://img1.qunarzz.com/piao/fusion/1809/ff/1bf7d3a4f6591002.jpg_750x200_40809f2a.jpg" alt="">
      </swiper-slide>
      <swiper-slide>
        <img class="swiper-img" src="http://img1.qunarzz.com/piao/fusion/1809/d4/e298dff35d3af802.jpg_750x200_9b0d56c1.jpg" alt="">
      </swiper-slide> -->
      <swiper-slide v-for="item of list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" alt="">
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true,
        autoplay: 2000,
        speed: 1000
      }
    }
  },
  computed: {
    showSwiper () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped>
.wrapper >>> .swiper-pagination-bullet-active
  background #fff
  // 意思是让这个样式穿透 只要是在.wrapper下的子组件有这个类名 就让它把样式加上去
.wrapper
  height 0
  overflow hidden
  padding-bottom 31.25%
  // padding和margin的百分比设置是相对于父元素的width 这样就可以形成宽高的百分比
  // 如果设置height为百分比的话 百分比是相对于其父元素的height
  background-color #eee
  .swiper-pagination-bullet-active
    background red !important
  // 这样写并不会有效果 因为当前的style设置scoped 样式只对当前组件生效，而小圆点的样式是在swiper这个组件上的
  .swiper-img {
    width: 100%;
}
</style>
